/**
  * <br>JAVACC DEMO 1.0<br>
  * <br>
  * @Package com.using.weixin.wxtools.manager.impl
*/
package com.apache.portal.weixin.core.manager.impl.send;

import com.apache.portal.common.util.EnumUtil.ResMsgEnum;
import com.apache.portal.weixin.core.common.BaseService;
import com.apache.portal.weixin.core.common.LoadService;
import com.apache.portal.weixin.core.manager.ResMsgManager;
import com.apache.portal.weixin.entity.BaseVo;
import com.apache.portal.weixin.entity.recv.WxRecvMsg;
import com.apache.portal.weixin.entity.recv.WxRecvPicMsg;
import com.apache.portal.weixin.entity.send.WxSendMsg;
import com.apache.portal.weixin.entity.send.WxSendPicMsg;
import com.apache.portal.weixin.entity.send.WxSendTextMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
  * description: 图片消息回复接口实现
  * @author Hou DaYu 创建时间：上午09:45:54
  */
public class PicMsgManagerImpl implements ResMsgManager {

	private Logger log = LoggerFactory.getLogger(PicMsgManagerImpl.class);

	/* (non-Javadoc)
	 * @see com.using.weixin.wxtools.manager.ResMsgManager#execute(com.using.weixin.wxtools.manager.ResMsgManager.ResMsgEnum, com.using.weixin.wxtools.vo.recv.WxRecvMsg)
	 */
	public WxSendMsg execute(ResMsgEnum resMsg, WxRecvMsg wxRecvMsg) {
		WxSendMsg sendMsg = null;
		try {
			switch (resMsg) {
			case pic:
				sendMsg = getWxSendPicMsg((WxRecvPicMsg) wxRecvMsg);
				break;
			}
		} catch (Exception e) {
			sendMsg = LoadService.getInstance().getTools().builderSendByRecv(wxRecvMsg);
			sendMsg = new WxSendTextMsg(sendMsg, "请您稍后关注，版本更新中...");
			log.error("异常",e);
		}
		return sendMsg;
	}

	private WxSendMsg getWxSendPicMsg(WxRecvPicMsg wxRecvMsg) throws Exception {
		BaseService service = LoadService.getInstance().getBeans("service_pic");
		WxSendMsg sendMsg = null;
		if (null == service) {
			sendMsg = LoadService.getInstance().getTools().builderSendByRecv(wxRecvMsg);
			sendMsg = new WxSendPicMsg(sendMsg, "200039057");
		} else {
			BaseVo vo = new BaseVo();
			vo.setWxRecvMsg(wxRecvMsg);
			//vo.setParams("", "");
			sendMsg = (WxSendMsg) service.execute(vo);
		}
		return sendMsg;
	}

}
